package com.jsyh.maidu.presenter;

import android.content.Context;

import com.jsyh.maidu.config.ConfigValue;
import com.jsyh.maidu.http.BaseDelegate;
import com.jsyh.maidu.http.ExceptionHelper;
import com.jsyh.maidu.http.OkHttpClientManager;
import com.jsyh.maidu.model.BestNewHotModel;
import com.jsyh.maidu.model.SuppinfoModel;
import com.jsyh.maidu.utils.Utils;
import com.jsyh.maidu.views.StoreView;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by admin on 2017/7/17.
 */

public class SuppInfoPresenter extends BasePresenter {
    StoreView storyview;
    Context context;
    public SuppInfoPresenter(StoreView storyview,Context context)
    {
        this.context=context;
        this.storyview=storyview;
    }

    public void LaodSuppinfo(String suppid)
    {
        Map<String ,String > params=new HashMap<>();
        params.put("suppid",suppid);
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "stores/get_suppinfo", params, new BaseDelegate.ResultCallback<SuppinfoModel>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                Utils.showToast(context, ExceptionHelper.getMessage(e, context));
            }

            @Override
            public void onResponse(SuppinfoModel response, Object tag) {
                storyview.returnSuppInfo(response);
            }

        });
     }

     public void getShopGoodsList(String suppid, String page){
         initLoadDialog(context);
         mLoadingDialog.show();
         Map<String, String> param = new HashMap<>();
         param.put("suppid", suppid);
         param.put("page", page);
         OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "stores/get_supp_categoods", param,
                 new BaseDelegate.ResultCallback<BestNewHotModel>() {
                     @Override
                     public void onError(Request request, Object tag, Exception e) {
                         mLoadingDialog.dismiss();
                     }

                     @Override
                     public void onResponse(BestNewHotModel response, Object tag) {
                        mLoadingDialog.dismiss();
                         storyview.getShopGoodsList(response);
                     }
                 });

     }


    public void getShopCatGoodsList(String suppid, String cat_id,String page){
        initLoadDialog(context);
        mLoadingDialog.show();
        Map<String, String> param = new HashMap<>();
        param.put("suppid", suppid);
        param.put("cat_id",cat_id);
        param.put("page", page);
        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "stores/get_supp_categoods", param,
                new BaseDelegate.ResultCallback<BestNewHotModel>() {
                    @Override
                    public void onError(Request request, Object tag, Exception e) {
                        mLoadingDialog.dismiss();
                    }

                    @Override
                    public void onResponse(BestNewHotModel response, Object tag) {
                        mLoadingDialog.dismiss();
                        storyview.getShopGoodsList(response);
                    }
                });

    }
}
